/**
 * 抽象设计模式
 */
public class AbstractFactoryTest {
    public static void main(String[] args){
        IDatabaseUtils IDatabaseUtils = new OracleDatabaseUtils();
        IConnection connection = IDatabaseUtils.getConnection();
        connection.connect();
        ICommand command = IDatabaseUtils.getCommand();
        command.command();
    }
}
//抽象连接方法
interface IConnection{
    void connect();
}
//抽象命令方法
interface ICommand{
    void command();
}
//抽象数据库工具接口
interface IDatabaseUtils{
    IConnection getConnection();
    ICommand getCommand();
}
//mysql连接对象
class MysqlConnection implements IConnection{

    @Override
    public void connect() {
        System.out.println("mysql连接");
    }
}
//Oracle连接对象
class OracleConnection implements IConnection{
    @Override
    public void connect() {
        System.out.println("Oracle连接");
    }
}
//mysql发生命令对象
class MysqlCommand implements ICommand{
    @Override
    public void command() {
        System.out.println("mysql发送命令");
    }
}
//oracle发生命令对象
class OracleCommand implements ICommand{
    @Override
    public void command() {
        System.out.println("Oracle发送命令");
    }
}
//mysql工具类
class MysqlDatabaseUtils implements IDatabaseUtils{
    @Override
    public IConnection getConnection() {
        return new MysqlConnection();
    }

    @Override
    public ICommand getCommand() {
        return new MysqlCommand();
    }
}
//oracle工具类
class OracleDatabaseUtils implements IDatabaseUtils{
    @Override
    public IConnection getConnection() {
        return new OracleConnection();
    }

    @Override
    public ICommand getCommand() {
        return new OracleCommand();
    }
}